﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="del_staff.aspx.cs" Inherits="SQT.tracnghiem.Ajax.ASP.Staff.del_staff" %>

<%@ Import Namespace="DataAccess" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<body>
    <%
        int id = int.Parse(Request.QueryString["id"]);

        var get_test = new TblTestController().FetchAll().Where(x => x.TestCreator == id).ToList();
        var get_check = new TblCheckManagerController().FetchAll().Where(x => x.ManagerId == id);
        foreach (TblCheckManager chk in get_check)
        {
            new TblCheckManagerController().Destroy(chk.Id);
        }
        if (get_test.Count != 0)
        {        
            for(int i=0;i<get_test.Count;i++)
            {
                var get_td = new TblTestDetailController().FetchAll().Where(x => x.TestId == get_test[i].TestId).ToList();
                if (get_td.Count != 0)
                {
                    for(int j=0;j<get_td.Count;i++)
                    {
                        var get_ques = new TblQuestionController().FetchAll().Where(x => x.QuestionId == get_td[i].TestDetailId).ToList();
                        if (get_ques.Count != 0)
                        {
                            foreach (TblQuestion ques in get_ques)
                            {
                                new TblQuestionController().Destroy(ques.QuestionId);
                            }
                            new TblTestDetailController().Destroy(get_td[i].TestDetailId);
                        }
                        else
                        {
                            new TblTestDetailController().Destroy(get_td[i].TestDetailId);
                        }
                        new TblTestController().Destroy(get_test[i].TestId);
                    }
                }
                else
                {
                    new TblTestController().Destroy(get_test[i].TestId);
                }
            }
            new TblManagerController().Destroy(id);
        }
        else
        {
            new TblManagerController().Destroy(id);
        }
    %>
</body>
</html>
